package com.slz3.business.module.goodsManagement.gooBaseGoodsAttribute.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.slz3.business.frame.enums.AuditFlag;
import com.slz3.business.frame.enums.UsingFlag;
import com.slz3.business.frame.functions.Add;
import com.slz3.business.frame.functions.Modify;
import com.slz3.business.frame.module.DomainEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.time.LocalDate;
import java.util.UUID;

import static javax.persistence.EnumType.STRING;

@MappedSuperclass
@Data
@EqualsAndHashCode(callSuper = false)
public class GooBaseGoodsAttributeEntity extends DomainEntity {

    private UUID memberUUID;

    /**
     * 备注
     */
    @Basic(fetch = FetchType.LAZY)
    @Type(type = "text")
    private String serMemo;

    /**
     * 审核状态
     */
    @Enumerated(STRING)
    @NotNull(message = "serAudit 必须非空!", groups = {Add.class})
    @Null(message = "serAudit 必须为空!", groups = {Modify.class})
    private AuditFlag serAudit = AuditFlag.APPROVED;

    /**
     * 启用状态
     */
    @Enumerated(STRING)
    private UsingFlag serUsing = UsingFlag.ENABLE;

    /**
     * 标签
     */
    private String serLabels;



    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private LocalDate serInputGroupData;

    /**
     * 属性名称,做了冗余处理,来源GooAttribute-> name
     */
    @Column
    @NotBlank(message = "name 必须非空!", groups = {Add.class})
    @Length(min = 1, max = 16, message = "name must be between {min} and {max}", groups = {Add.class, Modify.class})
    private String name;

    @Column
    @NotNull(message = "fkGooAttributeUUID 必须非空!", groups = {Add.class})
    private UUID fkGooAttributeUUID;

    @Column
    @NotNull(message = "fkBaseGoodsUUID 必须非空!", groups = {Add.class})
    private UUID fkBaseGoodsUUID;

    /**
     * 该属性在规格中的排列位置
     */
    @NotNull(message = "serOrder 必须非空!", groups = {Add.class})
    private Integer serOrder;

}
